﻿#include "pch.h"

CIParaWrapper::CIParaWrapper()
{
    memset((void *)this, 0, sizeof(CIParaWrapper));
}

void CIParaWrapper::printSelf(char *captionUpper, int32_t)
{
    char caption[1024];
    sprintf(caption, "%s:%s", captionUpper, "CIParaWrapper");
    print4x(this, sizeof(CIParaWrapper), caption);
    if (this->head)
    {
        sprintf(caption, "%s:%s", captionUpper, "CIParaWrapper.head");
        print4x(this->head, this->size * this->len, caption);
    }
    if (this->num)
    {
        sprintf(caption, "%s:%s", captionUpper, "CIParaWrapper.num");
        print4x(this->num, sizeof(int32_t), caption);
    }
}

// sub_1001D040
CIParaWrapper *CIParaWrapper::init(LPVOID ipara)
{
    this->init_(ipara);
    return this;
};

// sub_1001DD10
CIParaWrapper *CIParaWrapper::init_(LPVOID ipara)
{
    this->init__(ipara);
    *(this->num) = 1;
    return this;
};

// sub_1001E220
CIParaWrapper *CIParaWrapper::init__(LPVOID ipara)
{
    this->head = ipara;
    this->size = 108;
    this->len = 1;
    this->tail = 0;
    this->needFreeHead = false;
    this->num = &(this->numValue);
    return this;
};

// sub_10019C80
float CIParaWrapper::getIParaInitTime()
{
    return ((TIPara *)(this->head))->initTime;
};

// sub_1001D2F0
CBaseWrapper *CIParaWrapper::close(char flag)
{
    this->close();
    if (flag & 1)
    {
        delete this;
        return NULL;
    }
    return this;
};

// sub_1001D620
CBaseWrapper *CIParaWrapper::close()
{
    return this->close_();
};

// sub_1001C620
int32_t CIParaWrapper::getTprgUsed()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->tprgUsed;
};

// sub_10019BF0
double CIParaWrapper::getStopTime()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->stopTime;
};

// sub_1001D6A0
CIParaWrapper *CIParaWrapper::setStopTime(float stopTime)
{
    TIPara *pTIPara = (TIPara *)this->head;
    pTIPara->stopTime = stopTime;
    return this;
};

// sub_100199E0
double CIParaWrapper::getSlope()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->slope;
};

// sub_100199C0
int32_t CIParaWrapper::getWidth()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->width;
};

// sub_10019A00
double CIParaWrapper::getDrift()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->drift;
};

// sub_10019A20
PKWD_MODE CIParaWrapper::getWdMode()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->wdMode;
};

// sub_10019A40
double CIParaWrapper::getTdouble()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->tdouble;
};

// sub_10019A60
int32_t CIParaWrapper::getMinHeight()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->minHeight;
};

// sub_10019A80
int32_t CIParaWrapper::getMinArea()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->minArea;
};

// sub_10019AA0
int32_t CIParaWrapper::getTailMode()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->tailMode;
};

// sub_10019AC0
int32_t CIParaWrapper::getAutoNegative()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->autoNegative;
};

// sub_10019AE0
int32_t CIParaWrapper::getShouldSens()
{
    TIPara *pTIPara = (TIPara *)this->head;
    return pTIPara->shouldSens;
};

// sub_10019820
void CIParaWrapper::validateWidthAndPkWidth(float rTime)
{
    TIPara *pTIPara = (TIPara *)this->head;
    if (pTIPara->pkWidth >= 1.0e-30 || pTIPara->width <= 0)
    {
        if (pTIPara->pkWidth > 1.0e-30)
        {
            pTIPara->width = (int32_t)(pTIPara->pkWidth * 10.0 * rTime / 3.0 + 0.5);
            if (!pTIPara->width)
            {
                pTIPara->width = 1;
            }
        }
    }
    else
    {
        pTIPara->pkWidth = (float)((double)pTIPara->width * 3.0 / (10.0 * rTime));
    }
};

// sub_100198D0
int32_t CIParaWrapper::validateSlopeAndpkNoise()
{
    TIPara *pTIPara = (TIPara *)this->head;
    if (pTIPara->pkNoise || pTIPara->slope <= 0.00001)
    {
        if (pTIPara->pkNoise > 0)
        {
            pTIPara->slope = (float)((double)pTIPara->pkNoise / 10.0);
        }
    }
    else
    {
        pTIPara->pkNoise = (int32_t)(pTIPara->slope * 10.0);
    }
    return 0;
};

// sub_10019940
void CIParaWrapper::validateWidthAndPkDrift(float scale)
{
    TIPara *pTIPara = (TIPara *)this->head;
    if (pTIPara->pkDrift == 0.0 && pTIPara->drift > 0.00001)
    {
        pTIPara->pkDrift = scale * pTIPara->drift;
    }
    else if (pTIPara->pkDrift > 0.0)
    {
        pTIPara->drift = pTIPara->pkDrift / scale;
    }
};

// sub_10019CA0
CIParaWrapper *CIParaWrapper::setWidth(int32_t width)
{
    TIPara *pTIPara = (TIPara *)this->head;
    pTIPara->width = width;
    return this;
};

// sub_10019CC0
CIParaWrapper *CIParaWrapper::setSlope(float slope)
{
    TIPara *pTIPara = (TIPara *)this->head;
    pTIPara->slope = slope;
    return this;
};

// sub_10019CE0
CIParaWrapper *CIParaWrapper::setDrift(float drift)
{
    TIPara *pTIPara = (TIPara *)this->head;
    pTIPara->drift = drift;
    return this;
};

// sub_10019D00
CIParaWrapper *CIParaWrapper::setTestPkWidth(float testPkWidth)
{
    TIPara *pTIPara = (TIPara *)this->head;
    pTIPara->testPkWidth = testPkWidth;
    return this;
};

// sub_10019D20
CIParaWrapper *CIParaWrapper::setTestPkNoise(int32_t testPkNoise)
{
    TIPara *pTIPara = (TIPara *)this->head;
    pTIPara->testPkNoise = testPkNoise;
    return this;
};

// sub_10019D40
CIParaWrapper *CIParaWrapper::setTestPkDrift(float testPkDrift)
{
    TIPara *pTIPara = (TIPara *)this->head;
    pTIPara->testPkDrift = testPkDrift;
    return this;
};
